package com.MedDroid.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import com.MedDroid.MainApp;
import com.MedDroid.R;
import com.MedDroid.task.LoadMedicalPageTask;

import java.util.ArrayList;

public class MedicalPageActivity extends Activity
{
	public ListView ListRecord;
	public ArrayList<String> CommentsList;
	public int LoadedUser;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.medical_page);

		Bundle extras = getIntent().getExtras();
		if (extras != null)
		{
			LoadedUser = extras.getInt("UserID");
		}

		ListRecord = (ListView) findViewById(R.id.listRecords);

        Button btnAddRecord = (Button) findViewById(R.id.btnAddMedicalRecord);
        btnAddRecord.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MedicalPageActivity.this, AddMedicalRecordActivity.class);
                startActivity(intent);
            }
        });
    }

	@Override
	public void onResume()
	{
		super.onResume();
		new LoadMedicalPageTask(((MainApp)getApplication()).getAuthentication(),((MainApp)getApplication()).getDatabase(), MedicalPageActivity.this).execute(LoadedUser);
	}

	public void makeList()
	{
		MainApp.log("Making list.");
		ArrayAdapter<String> adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, CommentsList);
		ListRecord.setAdapter(adapter);
	}
}